class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
    }
    OnPageLoad() {
        // 回车直接进行搜索
        $("panel_search").bind('keyup', function (e) {
            var key = e.keyCode;
            if (key === 13) {
                _Instance.FetchForPage(1);
            }
        });
        $('#loading').hide();
    }
    SetCriterion(item) {
        if (formatNullInputValue($.trim($("#StyleNoFilterValue").val())) !== null) {
            let _list = [];
            let _styleNo = $.trim($("#StyleNoFilterValue").val()).split('/');
            for (let i = 0; i < _styleNo.length; i++) {
                let _item = {};
                _item['StyleNo'] = $.trim(_styleNo[i]);
                _list.push(_item);
            }
            item['StyleNoList'] = _list;
        } else {
            item['StyleNoList'] = null;
        }
        item['SupplierName'] = $.trim($("#SupplierNameFilterValue").val());
        return item;
    }
    GetFilter() {
        let item = super.GetFilter(0);
        // 设置条件
        item = this.SetCriterion(item);
        return JSON.stringify(item);
    }
    EmptyTableContent() {
        $("#tab_data01 tbody").empty();
    }
    SetTableContent(result) {
        $("#tab_data01 tbody").empty();

        let content_01 = '';
        this.rows = result.length;
        let row_polinesid = "";
        for (let i = 0; i < result.length; i++) {
            if (result[i].days < 0) {
                content_01 += '<tr class="row__error">';
            } else {
                content_01 += '<tr>';
            }
            if (row_polinesid !== result[i].poLinesId) {
                content_01 += '<td rowspan="' + result[i].rows + '">' + formatNullData(result[i].poNo) + '</td>';
                content_01 += '<td rowspan="' + result[i].rows + '">' + formatNullData(result[i].supplierName) + '</td>';
                content_01 += '<td rowspan="' + result[i].rows + '">' + formatNullData(result[i].materialName) + '</td>';
                content_01 += '<td rowspan="' + result[i].rows + '">' + formatNullData(result[i].materialCode) + '</td>';
                content_01 += '<td rowspan="' + result[i].rows + '">' + formatNullData(result[i].specification) + '</td>';
                content_01 += '<td rowspan="' + result[i].rows + '">' + formatNullData(result[i].materialColourName) + '</td>';
                content_01 += '<td rowspan="' + result[i].rows + '" style="text-align:center;">' + formatNullData(result[i].uomName) + '</td>';
                content_01 += '<td rowspan="' + result[i].rows + '" style="text-align:right;">' + formatNullData(result[i].poQuantity) + '</td>';
                content_01 += '<td rowspan="' + result[i].rows + '">' + formatNullData(result[i].orderArrivalDate) + '</td>';
            }
            content_01 += '<td style="text-align:right;">' + formatNullData(result[i].stockInQuantity) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].arrivalDate) + '</td>';
            //content_01 += '<td style="text-align:right;">' + formatNullData(result[i].diffQuantity) + '</td>';
            if (row_polinesid !== result[i].poLinesId) {
                content_01 += '<td rowspan="' + result[i].rows + '" style="text-align:right;">' + formatNullData(result[i].diffQuantity) + '</td>';
                content_01 += '<td rowspan="' + result[i].rows + '" style="text-align:center;">' + formatNullData(result[i].days) + '</td>';
            } 
            content_01 += '</tr>';
            row_polinesid = result[i].poLinesId;

            $("#tab_data01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tab_data01");

        this.AutoAdjustTableHeightForLines();   // 自适应高度设置
        $(window).resize();                     // 防止因为出现滚动条而造成画面显示问题
        $('#loading').hide();
    }
    //《按钮》搜索
    DoSearch() {
        if (formatNullInputValue($.trim($("#StyleNoFilterValue").val())) === null &&
                formatNullInputValue($.trim($("#SupplierNameFilterValue").val())) === null) {
            ShowErrorMessagePanel('检索条件不能空。');
            return false;
        } else {
            this.FetchForPage(1);
        }
    }
    AutoAdjustTableHeightForLines() {
        let h = $(window).height();
        let _rc = Math.floor((h - 127 - 25) / 25);
        let _dh = _rc * 25;
        let _tah = this.rows * 25;
        _dh = (_tah >= _dh) ? _dh : _tah;

        $("#div_content").css({"max-height": _dh, height: _dh});
    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    $("#search_btn").hide(); // 无需搜索，隐藏搜索按钮
    // 设置数据补齐功能
    $("#StyleNoFilterValue").bigAutocomplete({
        url: parent.basePath + "/master/product/fetchSerialNoForAutoComplate.html"
    });
    _Instance = new MyPage(0, null, null, null, null, null, null, null,
            "/inventory/report/inv_detail/fetchAll.html",
            "");

    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    if (_Instance !== null)
        _Instance.AutoAdjustTableHeightForLines();
}
